//
//  main.cpp
//  CppPolyTest
//
//  Created by wangrui on 14-3-25.
//  Copyright (c) 2014年 PPS. All rights reserved.
//

#include <iostream>

/*
 *多态测试一
 *
 *
class A
{
public:
    static void testStaticMethod1()
    {
        std::cout<<"A:testStaticMethod1"<< std::endl;
    }
        
    virtual void testMethod1 ()
    {
        std::cout<<"A:testMethod1"<< std::endl;
    }
    
};


class B : public A
{
public:
//    分别注释查看效果
//    static void testStaticMethod1()
//    {
//        std::cout<<"B:testStaticMethod1"<< std::endl;
//    }
    
    void testMethod1 ()
    {
        std::cout<<"B:testMethod1"<< std::endl;
    }

    void testMethod1 (int x)
    {
        
    }
    
    void testMethod1 (float y)
    {
        
    }
    
 
    float testMethod1 (float y,int r)
    {
        return 0;
    }
};


class C : public B
{
    void testMethod1 ()
    {
        std::cout<<"B:testMethod1"<< std::endl;
    }
};


int main(int argc, const char * argv[])
{

    B *b = new B();
    B::testStaticMethod1();
    b->testMethod1();
    
    A *a = b;
    a->testMethod1();
    
    
    C *c = new C();
    B *bc = c;
    bc->testMethod1();
    
    
    C::testStaticMethod1();
    
    return 0;
}
*
*
*/



/*
 *
 *多态测试二 
 *
 *
#include <iostream>
#include <complex>

using namespace std;
class Base
{
public:
    virtual void f( int )
    {
        cout << "Base::f( int )" << endl;
    }
    
    virtual void f( double )
    {
        cout << "Base::f( double )" << endl;
    }
    
    virtual void g( int j = 10 )
    {
        cout << "Base::g()"<< j << endl;
    }
    
    virtual void test()
    {
        cout << "Base::test()" << endl;
    }
};


class Derived : public Base
{
public:
    
    void f ( complex <double>  )
    {
        cout << "Derived::f(complex)" << endl;
    }
    
    void g( int j = 20 )
    {
        cout << "Derived::g() " << j << endl;
    }
};


int main()
{
    Base b;
    Derived d;
    b.f(1.0);//Base::f( double )
    d.f(1.0);//Derived::f(complex)
    b.g();//Base::g()10
    d.g();//Derived::g() 20
    
    Base* pb = new Derived;
    pb->test();//Base::test(); //子类没有重写viturl函数时，还是调用父类的
    pb->f(1.0);//Base::f( double ) //子类没有重写父类的f(double)函数，只是重载，有一个同名的void f ( complex <double>  )，编译器把他编译成另外的函数名了
                                    //比如 f_comp()
    
    pb->g();//Derived::g() 10 //这个是重写
    
    delete pb;
}
*
*
*/



/*
 * 测试三: 继承时的声明
 *
 class A
 {
 public:
 static void testStaticMethod1()
 {
 std::cout<<"A:testStaticMethod1"<< std::endl;
 }
 
 void testMethod1()
 {
 std::cout<<"A:testMethod1"<< std::endl;
 }
 };
 
 
 class B : public A
 {
 public:
 static void testStaticMethod1();
 void testMethod1();
 };
 
 
 //1,要在某个类的作用域里实现某个方法, 该类必须声明该方法
 //2,外部调用之类的某个方法，如果子类没声明，则使用父类的方法
 void  B:: testStaticMethod1()
 {
 A::testStaticMethod1();
 std::cout<<"B:testStaticMethod1"<< std::endl;
 }
 
 void B:: testMethod1()//如果不声明,报错
 {
 std::cout<<"B:testMethod1"<< std::endl;
 }
 
 
 
 int main(int argc, const char * argv[])
 {
 
 //B::testStaticMethod1();
 
 B *b = new B();
 b->testMethod1(); //外部调用时，只要父类有声明就可以调用
 
 return 0;
 }
 
 */


/*
 *测试四:virtual关键字测试
 *
 class A
 {
 public:
 virtual void fun()
 {
 std::cout<<"A fun"<<std::endl;
 }
 };
 
 
 class B : public A
 {
 public:
 void fun()
 {
 std::cout<<"B fun"<<std::endl;
 }
 };
 
 
 
 int main(int argc, const char * argv[])
 {
 
 A *b = new B();
 b->fun(); //只有父类A加，而B不加virturl声明这种情况，仍然进行了多态 输出：B fun
 //实际上virturl是告诉编译器不要作静态绑定，运行时去查找
 
 return 0;
 }
 
 */


